﻿using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using atmGen;
using System.Data;
using System.Collections;
using System.Configuration;
using System.Collections.Generic;
using System.Reflection;

using System.Web.UI.HtmlControls;

namespace atmGen.ATMControlExtn
{
    /// <summary>
    /// Summary description for ATMControlExtn
    /// </summary>
    public class ATMControlExtn
    {
        public ATMControlExtn()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        #region Class support
        public class ControlExtender
        {
            public ControlExtender()
            {
            }

            public void setTextDateExtender(Control[] txtbxs)
            {
                foreach (Control txtbx in txtbxs)
                {
                    setTextDateExtender(txtbx, true);
                }
            }
            public void setTextDateExtender(Control txtbx)
            {
                setTextDateExtender(txtbx, true);
            }
            public void HideCalendar(Control txtbx, bool visible)
            {
              if(atm_Gen.ReadOnlyAll)  return;
                string id = txtbx.ID;
                string uniqueid = txtbx.Parent.ID + id;
                string tdeimgID = "IMG" + uniqueid;
                string tdemkvdrID = "MEV" + uniqueid;
                string tdemkedID = "MEE" + uniqueid;
                string tdecalID = "CAL" + uniqueid;
                Control ctrl = atm_Gen.SearchControl(txtbx.Parent, tdeimgID);
                if (ctrl != null)
                {
                    ctrl.Visible = visible;
                }
            }
            public void setTextDateExtender(Control txtbx, bool addBtnCalendar)
            {
                if (atm_Gen.ReadOnlyAll) return;
                string id = txtbx.ID;
                string uniqueid = txtbx.Parent.ID+id;
                string tdeimgID = "IMG" + uniqueid;
                string tdemkvdrID = "MEV" + uniqueid;
                string tdemkedID = "MEE" + uniqueid;
                string tdecalID = "CAL" + uniqueid;
                short TabIndex = 0;
                //PropByName pname = new PropByName(txtbx);
                ControlCollection pagectrl = txtbx.Parent.Controls;
                if (atm_Gen.SearchControl(txtbx.Parent, tdemkvdrID) != null) { return; }
                if (txtbx is SDSTextBox.SDSTextBox)
                {
                    if ((txtbx as SDSTextBox.SDSTextBox).ReadOnly) { return; }
                    (txtbx as SDSTextBox.SDSTextBox).Attributes["style"] = "text-align:justify;width:6em;";
                    //txtbx.Text = "";// "'<%# Bind(\"D1\", \"{0:dd/MM/yyyy}\") %>'";
                    (txtbx as SDSTextBox.SDSTextBox).ValidationGroup = "MKE";
                    (txtbx as SDSTextBox.SDSTextBox).MaxLength = 1;
                    TabIndex=(txtbx as SDSTextBox.SDSTextBox).TabIndex;
                }
                else
                {
                    if ((txtbx as TextBox).ReadOnly) { return; }
                    (txtbx as TextBox).Attributes["style"] = "text-align:justify;width:6em;";
                    //txtbx.Text = "";// "'<%# Bind(\"D1\", \"{0:dd/MM/yyyy}\") %>'";
                    (txtbx as TextBox).ValidationGroup = "MKE";
                    (txtbx as TextBox).MaxLength = 1;
                    TabIndex = (txtbx as TextBox).TabIndex;
                }
                
                if (addBtnCalendar)
                {

                    ImageButton btn = new ImageButton();
                    btn.ID = tdeimgID;
                    pagectrl.AddAt(pagectrl.IndexOf(txtbx) + 1, btn);
                    btn.ImageUrl = "~/images/calendar16.png";
                    btn.Attributes["style"] = "Width:16px; Height:16px;";
                    btn.CausesValidation = false;
                }
                Panel pnl = new Panel();
                pnl.ID = "pnl" + id;
                pagectrl.AddAt(TabIndex + 2, pnl);
                pnl.Attributes["style"] = "display:none;";
                
            }
        }
        #endregion Classs support
    }
}